"use strict";
cc._RF.push(module, '4b948qB5mFDXr/3y7SB1D2f', 'PKSpinningBlade');
// scripts/PKSpinningBlade.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _i,
    n = void 0 && (void 0).__extends || (_i = function i(t, e) {
  return (_i = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _i(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    a = void 0 && (void 0).__decorate || function (t, e, o, i) {
  var n,
      a = arguments.length,
      r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);else for (var s = t.length - 1; s >= 0; s--) {
    (n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
  }
  return a > 3 && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var r = t("GameConstant"),
    s = t("Util"),
    l = cc._decorator,
    c = l.ccclass,
    d = l.property,
    h = function (t) {
  function e() {
    var e = null !== t && t.apply(this, arguments) || this;
    return e.arrNode_Lever = new Array(3), e.arrNode_Blade = new Array(3), e.arrCollider_Blade = new Array(3), e.arrSp_effect_left = new Array(3), e.arrSp_effect_right = new Array(3), e.node_Lever = null, e.node_Blade = null, e.collider_Blade = null, e.sp_effect_left = null, e.sp_effect_right = null, e.nMaxNum = 3, e.isStartMove = !1, e.bAdvance = !1, e.bBackOut = !1, e.isGameOver = !1, e.nStarLeverWidth = 200, e.nEndLeverWidth = 400, e.nBladePosX = 85, e._weaponTag = 0, e._gameConstrol = null, e.posEffect_left = cc.v2(0, 0), e.posEffect_right = cc.v2(0, 0), e.collidIndex = 0, e.nAudioID = 0, e;
  }

  return n(e, t), e.prototype.init = function (t, e) {
    this._weaponTag = e, this._gameConstrol = t;

    for (var o = 0; o < this.nMaxNum; o++) {
      this.arrCollider_Blade[o].tag = e;
    }

    e == r.Collide_Weapon_Tag.SceneLeft_Saw ? (this.node.position = cc.v3(-cc.winSize.width / 2, this.getSceneSawY(), 0), this.node.scaleX = 1) : e == r.Collide_Weapon_Tag.SceneRight_Saw && (this.node.position = cc.v3(cc.winSize.width / 2, this.getSceneSawY(), 0), this.node.scaleX = -1);
  }, e.prototype.getSceneSawY = function () {
    return 0;
  }, e.prototype.onLoad = function () {
    for (var t = 0; t < this.nMaxNum; t++) {
      this.arrSp_effect_left[t].node.active = !1, this.arrSp_effect_right[t].node.active = !1;
    }

    this.isStartMove = !1, this.nStarLeverWidth = this.node_Lever.width, this.nBladePosX = this.node_Lever.x, this.nEndLeverWidth = this.nStarLeverWidth + cc.winSize.width / 2, this.initData();
  }, e.prototype.update = function () {
    if (this.isStartMove) {
      if (this.bAdvance) {
        for (var t = 0; t < this.nMaxNum; t++) {
          this.arrNode_Lever[t].width = this.arrNode_Lever[t].width + 1, this.arrNode_Blade[t].x = this.arrNode_Blade[t].x + 1, this.arrSp_effect_left[t].node.x = this.arrSp_effect_left[t].node.x + 1, this.arrSp_effect_right[t].node.x = this.arrSp_effect_right[t].node.x + 1;
        }

        this.node_Lever.width > this.nEndLeverWidth && (this.bAdvance = !1);
      }

      if (this.isGameOver) {
        for (t = 0; t < 3; t++) {
          this.arrNode_Lever[t].width = this.arrNode_Lever[t].width - 10, this.arrNode_Blade[t].x = this.arrNode_Blade[t].x - 10, this.arrSp_effect_left[t].node.x = this.arrSp_effect_left[t].node.x - 10, this.arrSp_effect_right[t].node.x = this.arrSp_effect_right[t].node.x - 10;
        }

        this.node_Lever.width < this.nStarLeverWidth && (this.isStartMove = !1);
      }
    }
  }, e.prototype.initData = function () {
    this.isGameOver = !1, this.isStartMove = !1;

    for (var t = 0; t < 3; t++) {
      this.arrNode_Lever[t].width = this.nStarLeverWidth, this.arrNode_Blade[t].x = this.nBladePosX;
    }

    this.stopAnimation();
  }, e.prototype.onGameStart = function () {}, e.prototype.onGameOver = function () {}, e.prototype.onGameBoutStart = function () {
    var t = this;
    this.isGameOver = !1, this.scheduleOnce(function () {
      t.isGameOver || (t.isStartMove = !0, t.bAdvance = !0, t.bBackOut = !1, s.Util.vibrateLong(), t.playAnimation());
    }, r.SceneSaw_Time_Start);
  }, e.prototype.onGameBoutOver = function () {
    this.isGameOver = !0, this.isStartMove = !0, this.stopAnimation();
  }, e.prototype.onBackOut = function () {
    this.isGameOver || (this.bAdvance = !1, this.bBackOut = !0);
  }, e.prototype.isAdvanceing = function () {
    return this.bAdvance;
  }, e.prototype.onAdvance = function () {
    var t = this;
    this.scheduleOnce(function () {
      t.isGameOver || (t.isStartMove = !0, t.bAdvance = !0, t.bBackOut = !1, t.playAnimation());
    }, 5);
  }, e.prototype.playAnimation = function () {
    for (var t = 0; t < 3; t++) {
      this.arrNode_Blade[t].stopAllActions(), cc.tween(this.arrNode_Blade[t]).by(.5, {
        angle: 360
      }).repeatForever().start();
    }
  }, e.prototype.stopAnimation = function () {
    for (var t = 0; t < 3; t++) {
      this.arrNode_Blade[t].stopAllActions();
    }
  }, e.prototype.damageEffect = function (t, e) {
    var o = this;

    if (!this.isGameOver) {
      var i = null,
          n = cc.v2(0, 0);

      if (t == r.Collide_Car_Tag.Left) {
        this.posEffect_left = this.setSpEffectPos(e), i = this.arrSp_effect_left[this.collidIndex], n = this.posEffect_left;
        var a = this.arrSp_effect_left[this.collidIndex].node.position;
        this.arrSp_effect_left[this.collidIndex].node.position = cc.v3(a.x + n.x, a.y + n.y, a.z);
      } else t == r.Collide_Car_Tag.Right && (this.posEffect_right = this.setSpEffectPos(e), i = this.arrSp_effect_right[this.collidIndex], n = this.posEffect_right, a = this.arrSp_effect_right[this.collidIndex].node.position, this.arrSp_effect_right[this.collidIndex].node.position = cc.v3(a.x + n.x, a.y + n.y, a.z));

      i && (i.node.active = !0, i.setAnimation(0, "animation", !0), this.playAudio(), cc.tween(i.node).delay(.5).call(function () {
        i.node.active = !1, o.stopAudio();
        var t = i.node.position;
        i.node.position = cc.v3(t.x - n.x, t.y - n.y, t.z);
      }).start());
    }
  }, e.prototype.setSpEffectPos = function (t) {
    for (var e = [], o = 0; o < this.nMaxNum; o++) {
      var i = this.arrNode_Blade[o].convertToWorldSpaceAR(cc.Vec2.ZERO);
      e[o] = t.sub(i).mag(), o > 0 && (e[o - 1] < e[o] ? (e[o] = e[o - 1], this.collidIndex = o - 1) : this.collidIndex = o);
    }

    var n = this.arrNode_Blade[this.collidIndex].convertToWorldSpaceAR(cc.Vec2.ZERO),
        a = s.Util.GetPointAngle(n, t),
        l = 70 * Math.cos(a),
        c = -70 * Math.sin(a);
    return this._weaponTag == r.Collide_Weapon_Tag.SceneRight_Saw && (l = -l, c = c), cc.v2(l, c);
  }, e.prototype.weaponLeaveCar = function (t) {
    var e = null,
        o = cc.v2(0, 0);

    if (t == r.Collide_Car_Tag.Left ? (e = this.sp_effect_left, o = this.posEffect_left, this.posEffect_left = cc.v2(0, 0)) : t == r.Collide_Car_Tag.Right && (e = this.sp_effect_right, o = this.posEffect_right, this.posEffect_right = cc.v2(0, 0)), e && e.node.active) {
      e.node.stopAllActions(), e.node.active = !1, this.stopAudio();
      var i = e.node.position;
      e.node.position = cc.v3(i.x - o.x, i.y - o.y, i.z), o = cc.v2(0, 0);
    }
  }, e.prototype.playAudio = function () {
    this.nAudioID = this._gameConstrol.playAudio(r.Game_Audio_ID.saw_hit);
  }, e.prototype.stopAudio = function () {
    this.nAudioID && this._gameConstrol.stopAudio(this.nAudioID);
  }, a([d(cc.Node)], e.prototype, "arrNode_Lever", void 0), a([d(cc.Node)], e.prototype, "arrNode_Blade", void 0), a([d(cc.CircleCollider)], e.prototype, "arrCollider_Blade", void 0), a([d(sp.Skeleton)], e.prototype, "arrSp_effect_left", void 0), a([d(sp.Skeleton)], e.prototype, "arrSp_effect_right", void 0), a([d(cc.Node)], e.prototype, "node_Lever", void 0), a([d(cc.Node)], e.prototype, "node_Blade", void 0), a([d(cc.CircleCollider)], e.prototype, "collider_Blade", void 0), a([d(sp.Skeleton)], e.prototype, "sp_effect_left", void 0), a([d(sp.Skeleton)], e.prototype, "sp_effect_right", void 0), a([c], e);
}(cc.Component);

o["default"] = h;

cc._RF.pop();